/**
 * 
 */
package edu.netjava.LinkList;

/**
 * @author Administrator
 * 
 */
public class LinkListTest {

	/**
	 * @param args
	 *            :the parameter for application
	 */
	public static void main(String[] args) {

		/**
		 * initial the list
		 */
		LinkList lkl = new LinkList();
		lkl.add("a");
		lkl.add("b");
		lkl.add("c");
		lkl.printAll();

		/**
		 * give users to input data
		 * 
		 */
		String str;
		int choice;
		java.util.Scanner sca = new java.util.Scanner(System.in);

		/**
		 * deal input in circle and takes next step
		 */
		boolean isExit = false;
		while (!isExit) {

			System.out.println("Please input the element:");
			String element = sca.next();
			lkl.add(element);
			System.out.println("Do you want to continue to input?y/n");
			str = sca.next();
			if (str.equalsIgnoreCase("n")) {
				isExit = true;
			}

		}

		/**
		 * give users detail prompts and guide operations
		 */
		isExit = false;
		while (!isExit) {
			System.out
					.println("Please give out your choice below:\n"
							+ "B,print elements\n" + "C,delete element\n"
							+ "D,find the element\n" + "F,insert element\n"
							+ "Q,exit!");
			str = sca.next();
			/**
			 * when chose ,print all elements in the list
			 */
			if (str.equalsIgnoreCase("B")) {
				System.out.println("all of the elements are:");
				System.out.println("-----------------------------");
				lkl.printAll();
				System.out.println("-----------------------------");
			} else if (str.equalsIgnoreCase("C")) {
				System.out.println("Please give out the index of the element:");
				choice = sca.nextInt();
				lkl.delete(choice);
				System.out.println("the element locate at " + choice
						+ " has been delete!\n");
			} else if (str.equalsIgnoreCase("D")) {
				System.out.println("Please give out the index of the element:");
				choice = sca.nextInt();
				System.out.println("This is the element you're looking for:");
				System.out.println("=====================");
				System.out.println(lkl.findNode(choice));
				System.out.println("=====================");
			} else if (str.equalsIgnoreCase("F")) {

				System.out
						.println("Please input the index of the inserting element:");
				choice = sca.nextInt();
				System.out.println("Please input the value of the element:");
				str = sca.next();
				lkl.insertNode(choice, str);
			} else if (str.equalsIgnoreCase("Q")) {
				isExit = true;
				System.out.println("the operation is over!");
			}
		}

		// Node node = new Node();
		// System.out.println(node);

	}

}
